import os

dirlist=[x for x in os.listdir() if os.path.isdir(x)]
for d in dirlist:
    #name=os.listdir(d)
    name=[x for x in os.listdir(d) if os.path.isfile(os.path.join(d,x))]
    #print(os.path.abspath('.'))
    try:
        onename=name[0]
    except:
        print('empty dir')
    try:
        cutname=onename.split("_")[0]
    except:
        print('no file')
	
    for n in name:
		
        if n.split('.')[-1]=='pkf':
	                
            os.remove(os.path.join(d,n))
            print('delete %s'%n)
    try:	
        os.rename(d,cutname)
        print('rename %s to %s'%(d,cutname))
    except:
        print('fail rename')
def main():
    
    print('done')
    os.system('pause')
if __name__ == '__main__':
	main()
